<!DOCTYPE html>
<html>
<head>
    <title>用户登录</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="lib/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-container" style="width: 400px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 100px;">
        <legend>用户登录</legend>
    </fieldset>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" autocomplete="off" placeholder="邮箱" class="layui-input emailVal">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" autocomplete="off" placeholder="密码" class="layui-input pwdVal">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn login">登录</button>
            </div>
        </div>
        <a href="http://127.0.0.1/static/register.html" style="float: right;margin: 30px;color: green;">注册新账号</a>
    </div>

</div>

<script src="lib/layui/layui.all.js"></script>
<script src="lib/jquery/jquery-3.4.1.min.js"></script>
<script>
    $(".login").click(function () {
        let pwd = $(".pwdVal").val();
        let email = $(".emailVal").val();
        let url = "http://127.0.0.1/api/user/login/" + email + "/" + pwd;
        $.ajax({
            url: url,
            type: "POST",
            success: function (result) {
                if (result === true) {
                    window.location.href = "http://127.0.0.1/static/welcome.html";
                } else {
                    layui.layer.msg("用户名或密码不正确",{
                        time: 1000
                    })
                }
            }
        });
    });
</script>
</body>
</html>